#pragma once
#include <glm/glm.hpp>
#include <glm/ext/scalar_constants.hpp>
struct Vertex {
    glm::vec3 position;
    glm::vec3 normal;
};
template <uint32_t segments = 32> struct Sphere {
    static constexpr uint32_t num_vertices = (segments + 1) * (segments + 1);
    static constexpr uint32_t num_indices = segments * segments * 6;

    Vertex vertices[num_vertices];
    uint32_t indices[num_indices];

    Sphere(float size = 1.0f) {
        const float pi = glm::pi<float>();
        uint32_t idx = 0;

        for (uint32_t k = 0; k <= segments; ++k) {
            float theta = pi * k / segments;
            float sin_theta = glm::sin(theta);
            float cos_theta = glm::cos(theta);

            for (uint32_t m = 0; m <= segments; ++m) {
                float phi = 2.0f * pi * m / segments;
                float sin_phi = glm::sin(phi);
                float cos_phi = glm::cos(phi);

                glm::vec3 normal(cos_phi * sin_theta, sin_phi * sin_theta, cos_theta);

                vertices[k * (segments + 1) + m] = {normal * size, normal};
            }
        }

        for (uint32_t k = 0; k < segments; ++k) {
            for (uint32_t m = 0; m < segments; ++m) {
                uint32_t i0 = k * (segments + 1) + m;
                uint32_t i1 = k * (segments + 1) + (m + 1);
                uint32_t i2 = (k + 1) * (segments + 1) + m;
                uint32_t i3 = (k + 1) * (segments + 1) + (m + 1);

                indices[idx++] = i0;
                indices[idx++] = i2;
                indices[idx++] = i1;

                indices[idx++] = i1;
                indices[idx++] = i2;
                indices[idx++] = i3;
            }
        }
    }
};